/*
 * Copyright (c) ycq_work@163.com
 */

package com.mxg.blog.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mxg.blog.entity.Article;
import com.mxg.blog.mapper.ArticleMapper;
import com.mxg.blog.service.ArticleService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: ycq_work@163.com
 * @DATE: 2023/5/8 22:54
 * article_server 接口具体实现
 */
@Service
public class ArticleServiceImpl extends ServiceImpl<ArticleMapper, Article> implements ArticleService {
    private final ArticleMapper articleMapper;

    public ArticleServiceImpl(ArticleMapper articleMapper) {
        this.articleMapper = articleMapper;
    }

    @Override
    public Article getArticleByArticleTitle(String articleTitle){
        return articleMapper.getArticleByArticleTitle(articleTitle);
    }

    // 新建原创文章
    @Override
    public void insertOriginalityArticle(String articleTitle, String articleContentHtml, String articleContentMd,
                                  Integer articleStatus, String articleTags,
                                  String articleImages, String articleExcerpt,
                                  Integer articleCategoryId){
        articleMapper.insertOriginalityArticle(articleTitle, articleContentHtml, articleContentMd,
                                               articleStatus, articleTags,
                                                articleImages, articleExcerpt,
                                                articleCategoryId);
    }

    // 新建非原创文章
    @Override
    public void insertUnoriginalityArticle(String articleTitle, String articleContentHtml, String articleContentMd,
                                    Integer articleStatus, String articleTags,
                                   /* Integer articleIsOriginal, String articleSourcesUrl,*/
                                    String articleImages, String articleExcerpt,
                                    Integer articleCategoryId){
        articleMapper.insertUnoriginalityArticle(articleTitle, articleContentHtml, articleContentMd,
                articleStatus, articleTags,
                /*articleIsOriginal, articleSourcesUrl,*/
                articleImages, articleExcerpt,
                articleCategoryId);
    }

    // 保存草稿
    @Override
    public void saveArticle (String articleTitle, String articleContentHtml, String articleContentMd, Integer articleStatus){
        articleMapper.saveArticle(articleTitle, articleContentHtml, articleContentMd, articleStatus);
    }


    // 更新文章
    @Override
    public void updateArticle (String articleTitle,  String articleContentHtml, String articleContentMd,
                               Integer articleStatus, String articleTags,
                               String articleImages, String articleExcerpt,
                               Integer articleCategoryId, Integer articleId){
        articleMapper.updateArticle (articleTitle, articleContentHtml, articleContentMd,
                                     articleStatus, articleTags,
                                     articleImages, articleExcerpt,
                                     articleCategoryId, articleId);

    }

    // 查询已发布的文章
    @Override
    public List<Article> getArticleByUserIdAndStatus1(Integer articleAuthorId){
        return articleMapper.getArticleByUserIdAndStatus1(articleAuthorId);
    }

    // 查询草稿的文章
    @Override
    public List<Article> getArticleByUserIdAndStatus2(Integer articleAuthorId){
        return articleMapper.getArticleByUserIdAndStatus2(articleAuthorId);
    }

    //查询已删除的文章
    @Override
    public List<Article> getArticleByUserIdAndStatus0(Integer articleAuthorId){
        return articleMapper.getArticleByUserIdAndStatus0(articleAuthorId);
    }

    // 根据文章分类查询文章
    @Override
    public List<Article> accordingToClassificationTheQuery(Integer articleAuthorId, Integer articleCategoryId){
        return articleMapper.accordingToClassificationTheQuery(articleAuthorId, articleCategoryId);
    }

    // 根据文章分类查询文章 已发布
    @Override
    public List<Article> accordingToClassificationTheQueryStatus1(Integer articleAuthorId, Integer articleCategoryId) {
        return articleMapper.accordingToClassificationTheQueryStatus1(articleAuthorId, articleCategoryId);
    }
    // 根据文章id查询文章
    public Article getArticleByArticleId(Integer articleId){
        return articleMapper.getArticleByArticleId(articleId);
    }

    // 逻辑删除文章
    public void deleteArticleStatus0(Integer articleId){
        articleMapper.deleteArticleStatus0(articleId);
    }

    // 恢复文章至草稿箱
    public void restoreDraftArticlesToBox(Integer articleId){
        articleMapper.restoreDraftArticlesToBox(articleId);
    }

    // 物理删除文章
    public void deleteParamsByIds(Integer articleId){
        articleMapper.deleteParamsByIds(articleId);
    }

    // 浏览量加一
    public void viewsPlusOne(Integer articleId){
        articleMapper.viewsPlusOne(articleId);
    }
}
